<template>
  <div class="booking">
    <div class="one">
      <p>物流名称</p>
      <input type="text" v-model="title" placeholder="请填写物流公司名称" />
    </div>
    <div class="one">
      <p>物流单号</p>
      <input
        type="text"
        v-model="number"
        placeholder="请输入邮寄的物流运单号"
      />
    </div>
    <div class="submit" @click="submit">确定</div>
  </div>
</template>
<script>
import { refund_add_poster } from "@api/order";
import cookie from "@utils/store/cookie";
import { clearAuthStatus } from "@libs/wechat";
import { mapGetters } from "vuex";
import { isWeixin } from "@utils";
import { setTimeout } from "timers";
export default {
  name: "bookingNote",
  data() {
    return {
      title: "",
      number: "",
      uni: ""
    };
  },
  components: {},
  computed: mapGetters(["userInfo"]),
  watch: {},

  methods: {
    //声音禁掉
    isNo: function() {
      var u = navigator.userAgent,
        app = navigator.appVersion;
      var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
      var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      const win = window;
      var obj = {
        action: "onClickPlay",
        content: {}
      };
      if (isAndroid) {
        App.onAppResponse(JSON.stringify(obj));
      }
      if (isIOS) {
        win.webkit.messageHandlers.onAppResponse.postMessage(
          JSON.stringify(obj)
        );
      }
    },
    getParameter: function() {
      var self = this;
      var u = navigator.userAgent,
        app = navigator.appVersion;
      var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
      var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      const win = window;
      var obj = {
        action: "getParameter",
        content: {
          method: "setUserInfo",
          Parameter: {}
        }
      };
      if (isAndroid) {
        App.onAppResponse(JSON.stringify(obj));
      }
      if (isIOS) {
        win.webkit.messageHandlers.onAppResponse.postMessage(
          JSON.stringify(obj)
        );
      }
    },
    // 嵌入app获取支付状态
    onWebResponse: function(str) {
      // alert(123);
      var obj = JSON.parse(str);
      var action = obj.action;
      var self = this;
      var content = obj.content;
      if (action == "setUserInfo") {
        let did = content.did;
        let isToken = content.ds_token;
        let expires_time = content.ds_expires_time;
        let isSalt = content.salt;
        if (isToken == "") {
          this.$store.commit(
            "LOGIN",
            isToken
            // dayjs(expires_time) - newTime
          );
        } else {
          let newTime = Math.round(new Date() / 1000);
          this.$store.commit(
            "LOGIN",
            isToken
            // dayjs(expires_time) - newTime
          );
        }
      }
    },
    submit: function() {
      if (this.title == "") {
        this.$dialog.toast({ mes: "请填写物流公司名称" });
        return;
      }
      if (this.number == "") {
        this.$dialog.toast({ mes: "请输入邮寄的物流运单号" });
        return;
      }
      refund_add_poster({
        poster_name: this.title,
        poster_num: this.number,
        uni: this.uni
      })
        .then(res => {
          if (res.status == "1") {
            this.$dialog.toast({ mes: "添加成功" });
          }
          setTimeout(() => {
            this.$router.go(-1);
          }, 1000);
        })
        .catch(res => {
          this.$dialog.error(res.msg);
        });
    }
  },
  created() {},
  mounted() {
    var that = this;
    var self = this;
    this.uni = this.$route.query.uni;
    if (this.$route.query.isToken) {
      this.$store.commit(
        "LOGIN",
        this.$route.query.isToken
        // dayjs(expires_time) - newTime
      );
      cookie.set("OID", this.$route.query.oId);
    }
    let isFromApp = this.$route.query.from1;
    this.from1 = isFromApp;
    console.log(this.from1);
    if (isFromApp == "app") {
      this.from1 = "app";
      if (cookie.get("from1") == "" || cookie.get("from1") == undefined) {
        cookie.set("from1", "app");
      }
      this.isNo();
      this.getParameter();
      window["onWebResponse"] = str => {
        that.onWebResponse(str);
      };
    } else if (isFromApp == "wxapp") {
    } else {
    }
    var u = navigator.userAgent,
      app = navigator.appVersion;
    var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
    var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  }
};
</script>
<style scoped>
.booking {
  padding-top: 0.26rem;
  width: 100%;
  height: 100%;
  background: #fff;
}
.one {
  width: 100%;
  height: auto;
}
.one p {
  padding-top: 0.32rem;
  padding-left: 0.48rem;
  padding-bottom: 0.24rem;
  font-size: 0.3rem;
  font-weight: 500;
  color: #000000;
  line-height: 0.42rem;
}
.one input {
  display: block;
  margin-left: 0.48rem;
  width: 6.24rem;
  height: 0.88rem;
  background: #f7f8f9;
  border-radius: 0.04rem;
  padding-left: 0.24rem;
  box-sizing: border-box;
}
.submit {
  margin: 2.42rem 1.68rem 0 1.42rem;
  width: 4.4rem;
  height: auto;
  background: #ff3c39;
  box-shadow: 0px 0.04rem 0.08rem 0px rgba(255, 60, 57, 0.2);
  border-radius: 0.44rem;
  font-size: 0.32rem;
  padding: 0.28rem 0;
  font-weight: 400;
  color: #ffffff;
  text-align: center;
  line-height: 1;
}
</style>
